<html>
<head><meta charset="utf-8"><title>Simplifying lowering code · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html">Simplifying lowering code</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209129080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129080">(Sep 04 2020 at 18:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Advice.20for.20.22Support.20extern.20opaque.20types.22/near/209118245">said</a>:</p>
<blockquote>
<p>(sidenote, the parser/lowering code is kind of over-complicated I think)</p>
</blockquote>
<p><span class="user-mention" data-user-id="232957">@Jack Huey</span> Anything in particular that caused you to say that?</p>



<a name="209129170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129170">(Sep 04 2020 at 18:55)</a>:</h4>
<p>Well</p>



<a name="209129210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129210">(Sep 04 2020 at 18:56)</a>:</h4>
<p>Uh, give me a minute to finish this review</p>



<a name="209129247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129247">(Sep 04 2020 at 18:56)</a>:</h4>
<p>I agree that the lowering code is kinda not really straightforward at the moment, but maybe you had something you ran into</p>



<a name="209129422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129422">(Sep 04 2020 at 18:58)</a>:</h4>
<p>Ah, looking at it now, just adding some <code>Default</code> impl for <code>Env</code> or something would help a bit already</p>



<a name="209129717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129717">(Sep 04 2020 at 19:01)</a>:</h4>
<p>(probably new() instead of Default, since Env holds references, but something like that)</p>



<a name="209129860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129860">(Sep 04 2020 at 19:02)</a>:</h4>
<p>Right so</p>



<a name="209129914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209129914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209129914">(Sep 04 2020 at 19:02)</a>:</h4>
<p>Starting with lowering</p>



<a name="209130070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130070">(Sep 04 2020 at 19:04)</a>:</h4>
<p>There's basically two different paths to lower things with generics</p>



<a name="209130101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130101">(Sep 04 2020 at 19:04)</a>:</h4>
<p>There's a lot of basically duplicate code</p>



<a name="209130206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130206">(Sep 04 2020 at 19:05)</a>:</h4>
<p>hmm, give an example?</p>



<a name="209130215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130215">(Sep 04 2020 at 19:05)</a>:</h4>
<p>Could probably have a single <code>Lower</code> trait</p>



<a name="209130256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130256">(Sep 04 2020 at 19:06)</a>:</h4>
<p>Example of duplicate code?</p>



<a name="209130264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130264">(Sep 04 2020 at 19:06)</a>:</h4>
<p>yeah</p>



<a name="209130290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130290">(Sep 04 2020 at 19:06)</a>:</h4>
<p>The <code>lookup_generic_arg</code> function</p>



<a name="209130314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130314">(Sep 04 2020 at 19:06)</a>:</h4>
<p>follows the pattern</p>
<div class="codehilite"><pre><span></span><code>if let Some(id) = ... {
  let k = ...;
  if k.binders.len(interner) &gt;0 {
....
}
</code></pre></div>



<a name="209130354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130354">(Sep 04 2020 at 19:07)</a>:</h4>
<p>Ah, you mean between the different maps</p>



<a name="209130418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130418">(Sep 04 2020 at 19:07)</a>:</h4>
<p>yes</p>



<a name="209130430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130430">(Sep 04 2020 at 19:07)</a>:</h4>
<p>(in that case)</p>



<a name="209130514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130514">(Sep 04 2020 at 19:08)</a>:</h4>
<p>Yeah, and all the lowering traits are overkill indeed</p>



<a name="209130606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130606">(Sep 04 2020 at 19:09)</a>:</h4>
<p>Or like, look at <code>lookup_apply_type</code></p>



<a name="209130625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130625">(Sep 04 2020 at 19:09)</a>:</h4>
<p>basically, lowering in tons of repeated code</p>



<a name="209130708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130708">(Sep 04 2020 at 19:10)</a>:</h4>
<p><code>parser.lalrpop</code>, I don't want to say too much about, because I don't know how much of the complexity is there out of necessity</p>



<a name="209130810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130810">(Sep 04 2020 at 19:11)</a>:</h4>
<p>Could probably also use some simplification, since the parser generates a _lot_ of code</p>



<a name="209130844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130844">(Sep 04 2020 at 19:11)</a>:</h4>
<p>So much so that we had that compile time problem a while ago</p>



<a name="209130851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209130851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209130851">(Sep 04 2020 at 19:11)</a>:</h4>
<p>Also true</p>



<a name="209131025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131025">(Sep 04 2020 at 19:13)</a>:</h4>
<p>(which reminds me, I should ask for the status on <a href="https://github.com/lalrpop/lalrpop/issues/543">lalrpop#543</a> so we can update to the newest version when the next version hits)</p>



<a name="209131058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131058">(Sep 04 2020 at 19:13)</a>:</h4>
<p>I wonder how much the parselib effort <em>might</em> help</p>



<a name="209131128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131128">(Sep 04 2020 at 19:14)</a>:</h4>
<p>I feel like we probably can't use it, since we need extra stuff</p>



<a name="209131286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131286">(Sep 04 2020 at 19:15)</a>:</h4>
<p>Hmm, yeah I don't think we could use that. And I'm not sure if that would be a lighter solution, since the whole rust parser is bigger than just what chalk needs</p>



<a name="209131308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131308">(Sep 04 2020 at 19:16)</a>:</h4>
<p>Yeah, exactly</p>



<a name="209131435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131435">(Sep 04 2020 at 19:17)</a>:</h4>
<p>My main gripe here though was <code>lowering.rs</code></p>



<a name="209131458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131458">(Sep 04 2020 at 19:17)</a>:</h4>
<p>Imo, a couple well placed macros could reduce the file length (and complexity) by 5 fold at least</p>



<a name="209131484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131484">(Sep 04 2020 at 19:17)</a>:</h4>
<p>(okay, maybe that's a little exaggerated)</p>



<a name="209131623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131623">(Sep 04 2020 at 19:19)</a>:</h4>
<p>Definitely. Alright, I'll see what I can do</p>



<a name="209131808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131808">(Sep 04 2020 at 19:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125131">detrumi</span> <a href="#narrow/stream/144729-wg-traits/topic/Simplifying.20lowering.20code/near/209130514">said</a>:</p>
<blockquote>
<p>Yeah, and all the lowering traits are overkill indeed</p>
</blockquote>
<p>If you're talking about the <code>trait LowerX</code> traits, those are required due to the orphan rule. <code>chalk-integration</code> can't impl functions directly onto <code>chalk-ir</code> types except through a local trait impl.</p>



<a name="209131902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131902">(Sep 04 2020 at 19:22)</a>:</h4>
<p>Well, yes we need an extension trait, but we don't need a new one for each <code>Defn</code></p>



<a name="209131965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131965">(Sep 04 2020 at 19:22)</a>:</h4>
<p>We can just have one like <code>trait Lower { type Lowered; fn lower(&amp;self, env: &amp;Env) -&gt; LowerResult&lt;Lowered&gt;; }</code></p>



<a name="209131978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131978">(Sep 04 2020 at 19:23)</a>:</h4>
<p>I think some of the lower functions take in more than just <code>Env</code></p>



<a name="209131989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131989">(Sep 04 2020 at 19:23)</a>:</h4>
<p><a href="https://github.com/rust-lang/chalk/blob/46344c8074f2a8b9a377a1281021bf879ff5cc60/chalk-integration/src/lowering.rs#L1919-L1925">https://github.com/rust-lang/chalk/blob/46344c8074f2a8b9a377a1281021bf879ff5cc60/chalk-integration/src/lowering.rs#L1919-L1925</a></p>



<a name="209131996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209131996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> memoryleak47 <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209131996">(Sep 04 2020 at 19:23)</a>:</h4>
<p>Most of the LowerTraits don't actually get the Env argument I think</p>



<a name="209132011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> memoryleak47 <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132011">(Sep 04 2020 at 19:23)</a>:</h4>
<p>Or at least a few</p>



<a name="209132027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132027">(Sep 04 2020 at 19:23)</a>:</h4>
<p>But it would be great to generalize it to a single trait if possible.</p>



<a name="209132145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132145">(Sep 04 2020 at 19:24)</a>:</h4>
<p>oh drat</p>



<a name="209132257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132257">(Sep 04 2020 at 19:26)</a>:</h4>
<p>so that's because <code>TraitDefn</code> doesn't know its own id?</p>



<a name="209132280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132280">(Sep 04 2020 at 19:26)</a>:</h4>
<p>Another option is to just not use traits, and instead just use freestanding functions</p>



<a name="209132349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132349">(Sep 04 2020 at 19:27)</a>:</h4>
<p>having a single trait so you can jump to all the implementations would be kinda nice though</p>



<a name="209132357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132357">(Sep 04 2020 at 19:27)</a>:</h4>
<p><code>LowerImpl</code> is also a good example of extra params: <a href="https://github.com/rust-lang/chalk/blob/46344c8074f2a8b9a377a1281021bf879ff5cc60/chalk-integration/src/lowering.rs#L1821-L1828">https://github.com/rust-lang/chalk/blob/46344c8074f2a8b9a377a1281021bf879ff5cc60/chalk-integration/src/lowering.rs#L1821-L1828</a></p>



<a name="209132526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132526">(Sep 04 2020 at 19:29)</a>:</h4>
<p>So <code>AssociatedTyValueIds</code> is passed directly instead of throught the environment?</p>



<a name="209132553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209132553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209132553">(Sep 04 2020 at 19:29)</a>:</h4>
<p>It may be able to be simplified; that's not out of the question :)</p>



<a name="209135358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209135358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209135358">(Sep 04 2020 at 20:02)</a>:</h4>
<p>First improvement: <code>self.lower_where_clauses(&amp;env)</code> can be simplified to <code>self.where_clauses.lower(&amp;env)</code>, removing the need for the whole <code>LowerWhereClauses</code> trait</p>



<a name="209143898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209143898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209143898">(Sep 04 2020 at 21:44)</a>:</h4>
<p>Can we merge some id maps such as adt_ids, fn_def_ids, closure_ids and opaque_ty_ids? Or could the names potentially overlap?</p>



<a name="209143954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209143954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209143954">(Sep 04 2020 at 21:45)</a>:</h4>
<p>ah, it's also passed on to <code>LoweredProgram</code>, so that wouldn't work</p>



<a name="209170696"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209170696" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209170696">(Sep 05 2020 at 09:52)</a>:</h4>
<p><a href="/user_uploads/4715/e9ExM13sOl4NhyRUu1ziT6A-/image.png">image.png</a> <br>
Heh, there's some old code in there that's not used any more</p>
<div class="message_inline_image"><a href="/user_uploads/4715/e9ExM13sOl4NhyRUu1ziT6A-/image.png" title="image.png"><img src="/user_uploads/4715/e9ExM13sOl4NhyRUu1ziT6A-/image.png"></a></div>



<a name="209173815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209173815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209173815">(Sep 05 2020 at 11:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232957">Jack Huey</span> <a href="#narrow/stream/144729-wg-traits/topic/Simplifying.20lowering.20code/near/209132280">said</a>:</p>
<blockquote>
<p>Another option is to just not use traits, and instead just use freestanding functions</p>
</blockquote>
<p>I'm now doing this for some functions such as <code>lower_adt</code>, but for other cases it has the downside of not being able to chain a <code>.lower(env)</code> at the end</p>



<a name="209173949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209173949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209173949">(Sep 05 2020 at 11:33)</a>:</h4>
<p>For example, compare these two calls. You'd also need to deref explicitly when calling it on <code>Box&lt;Goal&gt;</code></p>
<div class="codehilite"><pre><span></span><code>chalk_parse::parse_goal(text)?.lower(&amp;*program)
lower_goal(*chalk_parse::parse_goal(text)?, &amp;*program)
</code></pre></div>



<a name="209174025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209174025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209174025">(Sep 05 2020 at 11:35)</a>:</h4>
<p>At the moment I'm considering having a <code>Lower</code> trait for lowering without env, <code>LowerInEnv</code> with env, keep <code>LowerGoal</code> as is and convert others that take more parameters to freestanding functions</p>



<a name="209174081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209174081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209174081">(Sep 05 2020 at 11:37)</a>:</h4>
<p>I guess it's also possible to have a single lowering trait by making the argument generic like <code>LowerGoal</code> does, but that'd get hairy with passing tuples and such</p>



<a name="209180129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Simplifying%20lowering%20code/near/209180129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Simplifying.20lowering.20code.html#209180129">(Sep 05 2020 at 14:18)</a>:</h4>
<p>Those <code>lookup_generic_arg</code> and <code>lookup_apply_type</code> functions are rather confusing. I _think_ <code>lookup_generic_arg</code> could re-use <code>lookup_apply_type</code> if we add <code>ApplyTypeLookup::Param</code>, but then I'm left wondering what to do with <code>foreign_ty_ids</code> and <code>trait_ids</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>